package com.woniuxy.controller;

import com.woniuxy.model.Building;
import com.woniuxy.result.Result;
import com.woniuxy.service.BuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("building")
@CrossOrigin
public class BuildingController {

    @Autowired
    private BuildingService buildingService;

    //增
    @PostMapping("insert")
    public Result add(@RequestBody Building building){
        buildingService.addBuild(building);
        return Result.success().msg("新增建筑成功");
    }
    //删，根据id进行删
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Integer id){
        buildingService.deleteById(id);
        return Result.success().msg("删除成功");
    }

    //改，传入对象进行修改,根据传入的id
    @PutMapping("update")
    public Result update(@RequestBody Building building){
        buildingService.updateById(building);
        return Result.success().msg("修改楼房信息成功");
    }
    //查
    //1.查询所有的记录
    @GetMapping("select")
    public Result getAll(){
        List<Building> buildings = buildingService.selectAll();
        return Result.success(buildings).msg("查询所有记录成功");
    }

    //2.分页查询
    @GetMapping("page/{page}/{size}")
    public Result pageQuery(@PathVariable Integer page,@PathVariable Integer size,String remarks){
        List<Building> buildings = buildingService.pageQuery(page,size,remarks);
        return Result.success(buildings).msg("查询第"+page+"页 "+size+"条数据成功");
    }
}
